package com.easyboot.utils;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import com.easyboot.constant.CookieConstants;
import org.apache.tomcat.util.codec.binary.Base64;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;

public class EncryptUtils {
    //#s^un2ye21fcv%|f0XpR,+vh
    private static String DesKey="fofia@easyboot";

    /**
    *
     * @author yushuo
     * @description DES加密
     * @date 10:00 2021/7/6
     * @param [text]
     * @return java.lang.String
    **/
    public static String desEncrypt(String text){
        byte[] keyString=DesKey.getBytes();
        byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.DES.getValue(),keyString).getEncoded();
        SymmetricCrypto des = new SymmetricCrypto(SymmetricAlgorithm.DES, key);
        //加密为16进制表示
        String encryptHex = des.encryptHex(text);
        return encryptHex;
    }

    /**
    *
     * @author yushuo
     * @description DES解密
     * @date 10:01 2021/7/6
     * @param [text]
     * @return java.lang.String
    **/
    public static String desDecrypt(String text){
        byte[] keyString=DesKey.getBytes();
        byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.DES.getValue(),keyString).getEncoded();
        SymmetricCrypto des = new SymmetricCrypto(SymmetricAlgorithm.DES, key);
        //加密为16进制表示
        String decryptStr = des.decryptStr(text);
        return decryptStr;
    }

}
